﻿/*
 * @Autor: PK
 * @Date: 2022/06/17 11:33:SS
 */

using System;
using System.Collections.Generic;
using System.Data;
using ShkSimulation.core.dao.input.resource;
using ShkSimulation.core.factory;
using ShkSimulation.core.template.agency;
using ShkSimulation.core.template.model;

namespace ShkSimulation.highway {
	
	public class HighwayRunConfig {

		public static double DayArriveCount = 1200;
		
		public static double RoadSectionServiceRate = 2;
		public static int RoadSectionCapacity = 8;
		public static RoadSectionConfig[] RoadSectionConfigs = {
			// 一项表示一个路段，uniqueId是唯一区分键，order是路段的顺序
			new RoadSectionConfig(1, 1, RoadSectionServiceRate, RoadSectionCapacity),
			new RoadSectionConfig(2, 2, RoadSectionServiceRate, RoadSectionCapacity),
			new RoadSectionConfig(3, 3, RoadSectionServiceRate, RoadSectionCapacity),
			new RoadSectionConfig(4, 4, RoadSectionServiceRate, RoadSectionCapacity),
		};

	}

	public class RoadSectionCreateUtil {

		public static Agency CreateSingleAgency(IReadOnlyDictionary<int, Agency> createdAgencies, CreateParam createParam) {
			Dictionary<string, object> attributes = createParam.Params;
			int uniqueId = Convert.ToInt32(attributes["UniqueId"]);
			int order = Convert.ToInt32(attributes["Order"]);
			int capacity = Convert.ToInt32(attributes["Capacity"]);
			double roadSectionServiceRate = Convert.ToDouble(attributes["RoadSectionServiceRate"]);
			
			BaseAgencyParams agencyParams = BaseAgencyParams.Create(uniqueId);
			RoadSection section = new RoadSection(agencyParams);
			section.Order = order;
			section.Capacity = capacity;
			section.ServiceRateHelper = new StableServiceRateHelper(TimeSpan.FromHours(1 / roadSectionServiceRate));
			return section;
		}

		public static Dictionary<int, Agency> CreateByResource(Resource resource, List<CreateParam> createParams) {
			Dictionary<int, Agency> result = new Dictionary<int, Agency>();
			// 手动添加几个
			foreach (RoadSectionConfig roadSectionConfig in HighwayRunConfig.RoadSectionConfigs) {
				BaseAgencyParams agencyParams = BaseAgencyParams.Create(roadSectionConfig.UniqueId);
				RoadSection road = new RoadSection(agencyParams);
				road.Order = roadSectionConfig.Order;
				road.ServiceRateHelper = new StableServiceRateHelper(TimeSpan.FromHours(1 / roadSectionConfig.RoadSectionServiceRate));
				road.Capacity = roadSectionConfig.Capacity;
				result.Add(agencyParams.UniqueId, road);
			}
			return result;
		}

	}

}